import 'package:dio/dio.dart';

/// The [BaseDecoder] class is an abstract class provide a
/// method to decode the response data.
///
/// To use this class,
/// you can create a class that extends this class and
/// implement the [decode] method.Then setup of the decoder
/// this will be passed to the [CompactDioRequest] class
/// This method holds the response and the type of the
/// model you pass,you can make your own implementation
/// by this method.
///
///
/// If you want to raise an exception
/// please throw an [CompactDioException] exception.then the
/// exception will be caught by the [CompactDioRequest] class
/// and make this request as an error response,if you throw
/// otherwise the exception will not be caught.
///
/// ```dart
/// class ResultDecoder implements BaseDecoder {
///   static ResultDecoder? _decoder;
///
///   ResultDecoder._();

///   static get instance => _decoder ??= ResultDecoder._();

///   @override
///   R decode<R, T>({required Response<dynamic> response, T? type}) {
///     if (type is BaseModel) {
///      if (response.data is List) {
///         final dataList = response.data as List;
///         final newDataList = dataList.map((e) => type.fromJson(e)).toList();
///         return List<T>.from(newDataList) as R;
///       } else {
///         return type.fromJson(response.data) as R;
///       }
///     } else {
///       return response.data as R;
///     }
///   }
/// }
/// ```

abstract class BaseDecoder {
  R decode<R, T>({required Response response, T? type});
}
